﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Core;
using ZHDJ.Data.Models.BaseInfo;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Grassroots;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal.Grassroots
{
    public partial class ItemDetail : PortalPage
    {
        #region 页面属性

        public string ItemID
        {
            get { return this.Request["ItemID"] ?? "null"; }
        }

        private List<PartyGrassrootsGroupItemMember> _DataSource;

        public List<PartyGrassrootsGroupItemMember> DataSource
        {
            get
            {
                if (_DataSource == null)
                {
                    _DataSource = DB.PartyGrassrootsGroupItemMembers.Where(a => a.ItemID == ItemID).ToList();
                }
                return _DataSource;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            this.rptPost.ItemDataBound += RptPost_ItemDataBound;
            //基础信息
            var model = DB.PartyGrassrootsGroupItems.Find(ItemID);
            if (model==null)
            {
                RedirectToDefault();
            }
            txtTitle.Text=model.ItemName;
            litBranchName.Text = ControlBusiness.GetBranchPickerText(model.BranchID);
            litLinkAddress.Text = model.LinkAddress;
            litLinkMan.Text = model.LinkMan;
            litLinkMobileNo.Text = model.LinkMobileNo;
            litLinkTime.Text = model.LinkTime;

            //团队成员
            var postCategory = DB.DataDictionarys.Where(a => a.DDicType == SysDataDictionary.GrassrootsDutyCategory).OrderBy(a => a.OrderNo).ToList();
            rptPost.DataSource = postCategory;
            rptPost.DataBind();
        }

        private void RptPost_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var dataList = e.Item.FindControl("rptLeader") as Repeater;
            if (dataList == null)
            {
                return;
            }
            var row = e.Item.DataItem as DataDictionary;
            var list = DataSource.Where(a=>a.DutyCategory== row.DDicMember);
            
            dataList.DataSource = list;
            dataList.DataBind();
        }

    }
}